package de.uka.ilkd.key.dl.arithmetics.impl.metitarski;

import java.beans.BeanDescriptor;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;

import de.uka.ilkd.key.dl.arithmetics.impl.metitarski.Options;
import de.uka.ilkd.key.dl.options.EPropertyConstant;
import de.uka.ilkd.key.dl.options.FilePropertyEditor;

public class OptionsBeanInfo extends SimpleBeanInfo{

	private static final Class<Options> beanClass = Options.class;

	public OptionsBeanInfo() {
	}

	public BeanDescriptor getBeanDescriptor() {
		BeanDescriptor d = new BeanDescriptor(beanClass);
		d.setDisplayName("Meti-Tarski Options");
		d.setShortDescription("Set Meti-Tarski options and flags");
		return d;
	}
	
	public PropertyDescriptor[] getPropertyDescriptors() {
		try {
			PropertyDescriptor[] pds = new PropertyDescriptor[] {
					createDescriptor("metitBinary",
							EPropertyConstant.METIT_OPTIONS_BINARY, false,
							false, true, FilePropertyEditor.class),
					createDescriptor("backtracking",
							EPropertyConstant.METIT_OPTIONS_BACKTRACKING, false, false),
					createDescriptor("proj_ord",
							EPropertyConstant.METIT_OPTIONS_PROJ_ORD, false,
							false),
					createDescriptor("icp_cad",
							EPropertyConstant.METIT_OPTIONS_ICP_CAD, false,
							false),
					createDescriptor("icp",
							EPropertyConstant.METIT_OPTIONS_ICP, false,
							false),
					createDescriptor("unsafe_divisors",
							EPropertyConstant.METIT_OPTIONS_UNSAFE_DIVISORS,
							false, false),
							
							
					createDescriptor("full",
							EPropertyConstant.METIT_OPTIONS_FULL, false,
							false),
							
							
					createDescriptor("maxweight",
							EPropertyConstant.METIT_OPTIONS_MAXWEIGHT, false,
							false),
					createDescriptor("maxalg",
							EPropertyConstant.METIT_OPTIONS_MAXALG, false,
							false),
					createDescriptor("qlimit",
							EPropertyConstant.METIT_OPTIONS_QLIMIT, false,
							false),
					createDescriptor("cases",
							EPropertyConstant.METIT_OPTIONS_CASES, false,
							false),

			};
			return pds;
		} catch (IntrospectionException ex) {
			ex.printStackTrace();
			return null;
		}
	}
	
	private static PropertyDescriptor createDescriptor(String propertyName,
			EPropertyConstant propertyConstants) throws IntrospectionException {
		return createDescriptor(propertyName, propertyConstants, false);
	}

	private static PropertyDescriptor createDescriptor(String propertyName,
			EPropertyConstant propertyConstants, boolean expert)
			throws IntrospectionException {
		return createDescriptor(propertyName, propertyConstants, expert, false);
	}

	private static PropertyDescriptor createDescriptor(String propertyName,
			EPropertyConstant propertyConstants, boolean expert,
			boolean preferred) throws IntrospectionException {
		return createDescriptor(propertyName, propertyConstants, expert,
				preferred, null);
	}

	private static PropertyDescriptor createDescriptor(String propertyName,
			EPropertyConstant propertyConstants, boolean expert,
			boolean preferred, Class<?> propertyEditor)
			throws IntrospectionException {
		return createDescriptor(propertyName, propertyConstants, expert,
				preferred, false, null);
	}

	private static PropertyDescriptor createDescriptor(String propertyName,
			EPropertyConstant propertyConstants, boolean expert,
			boolean preferred, boolean hidden) throws IntrospectionException {
		return createDescriptor(propertyName, propertyConstants, expert,
				preferred, hidden, null);
	}

	private static PropertyDescriptor createDescriptor(String propertyName,
			EPropertyConstant propertyConstants, boolean expert,
			boolean preferred, boolean hidden, Class<?> propertyEditor)
			throws IntrospectionException {
		PropertyDescriptor result = new PropertyDescriptor(propertyName,
				beanClass);
		result.setDisplayName(propertyConstants.getLabel());
		result.setShortDescription(propertyConstants.getToolTip());
		result.setExpert(expert);
		result.setHidden(hidden);
		result.setPreferred(preferred);
		if (propertyEditor != null) {
			result.setPropertyEditorClass(propertyEditor);
		}
		return result;
	}
	
}
